#pragma once

#include <stdio.h>
#include <string.h>
#include "Renderer/OpenGL.h"

unsigned char *readShaderFile( const char *fileName );
void writeLog( const char *sLog );

class ShaderPack
{
private:
	GLhandleARB hShader;
	GLhandleARB hVs;
	GLhandleARB hPs;
public:
	void UniformParameter(char* sUniformName,GLfloat fField1)
	{
		glUniform1f(glGetUniformLocation(hShader, sUniformName), fField1);
	}
	void UniformParameter(char* sUniformName,GLfloat fField1,GLfloat fField2)
	{
		glUniform2f(glGetUniformLocation(hShader, sUniformName), fField1,fField2);
	}
	void UniformParameter(char* sUniformName,GLfloat fField1,GLfloat fField2,GLfloat fField3)
	{
		glUniform3f(glGetUniformLocation(hShader, sUniformName), fField1,fField2,fField3);
	}
	void UniformParameter(char* sUniformName,GLfloat fField1,GLfloat fField2,GLfloat fField3,GLfloat fField4)
	{
		glUniform4f(glGetUniformLocation(hShader, sUniformName), fField1,fField2,fField3,fField4);
	}
	void UniformTexture(char* sUniformName,int iField1)
	{
		glUniform1i(glGetUniformLocation(hShader, sUniformName),iField1);
	}
	void UniformParameter(char* sUniformName,UINT uField1)
	{
		glUniform1uiEXT(glGetUniformLocation(hShader, sUniformName),uField1);
	}
	void UseProgram()
	{
		glUseProgramObjectARB(hShader);
	}
	void UnUseProgram()
	{
		glUseProgramObjectARB(NULL);
	}
	GLhandleARB GetShader()
	{
		return hShader;
	}
	ShaderPack()
	{
		hShader = NULL;
	}
	bool CreateAndCompileShaders(char* sVsFile,char* sPsFile);
	void DestroyShaders()
	{
		if( hShader) {
			glDeleteObjectARB( hShader );
			hShader = NULL;
		}

		if( hVs) {
			glDeleteObjectARB( hVs );
			hVs = NULL;
		}

		if( hPs ){
			glDeleteObjectARB( hPs );
			hPs = NULL;
		}
	}
	~ShaderPack()
	{
		DestroyShaders();
	}
private:
	void WriteLogToFile(char *sLog)
	{
		writeLog(sLog);
	}
};

